package main

import (
	"fmt"
	"time"
)

// Counter代表计数器类型
type Counter struct {
	count int
}

var mapChan = make(chan map[string]Counter,1)

func main() {
	syncChan:=make(chan struct{},2)
	go func() {
		for{
			if elem,ok:=<-mapChan;ok{
				counter:=elem["count"]
				counter.count++
			}else {
				break
			}
		}
		fmt.Println("Stopped. [receiver]")
		syncChan<- struct{}{}
	}()

	go func() {
		countMap:=map[string]Counter{
			"count":{},
		}
		for i := 0; i < 5; i++ {
			mapChan<-countMap
			time.Sleep(time.Millisecond)
			fmt.Printf("The count map: %v. [sender]\n",countMap)
		}
		close(mapChan)
		syncChan<- struct{}{}
	}()

	<-syncChan
	<-syncChan
}
